<%@ CodePage=1252 %>
<%
'Include Common Files @1-FF2B2619
%>
<!-- #INCLUDE VIRTUAL="/fepace/Common.asp"-->
<!-- #INCLUDE VIRTUAL="/fepace/Cache.asp" -->
<!-- #INCLUDE VIRTUAL="/fepace/Template.asp" -->
<!-- #INCLUDE VIRTUAL="/fepace/Sorter.asp" -->
<!-- #INCLUDE VIRTUAL="/fepace/Navigator.asp" -->
<%
'End Include Common Files

'Initialize Page @1-EB31F616
' Variables
Dim PathToRoot, ScriptPath, TemplateFilePath
Dim FileName
Dim Redirect
Dim Tpl, HTMLTemplate
Dim TemplateFileName
Dim ComponentName
Dim PathToCurrentPage
Dim Attributes

' Events
Dim CCSEvents
Dim CCSEventResult

' Connections
Dim DBConnection1

' Page controls
Dim Header
Dim LinksSearch
Dim Links
Dim Footer
Dim ChildControls

Redirect = ""
TemplateFileName = "Links_list.html"
Set CCSEvents = CreateObject("Scripting.Dictionary")
PathToCurrentPage = "./"
FileName = "Links_list.asp"
PathToRoot = "./"
ScriptPath = Left(Request.ServerVariables("PATH_TRANSLATED"), Len(Request.ServerVariables("PATH_TRANSLATED")) - Len(FileName))
TemplateFilePath = ScriptPath
'End Initialize Page

'Authenticate User @1-8FF25281
CCSecurityRedirect "1;2", Empty
'End Authenticate User

'Initialize Objects @1-C2280645
Set DBConnection1 = New clsDBConnection1
DBConnection1.Open
Set Attributes = New clsAttributes

' Controls
Set Header = New clsHeader
Set Header.Attributes = Attributes
Header.Initialize "Header", ""
Set LinksSearch = new clsRecordLinksSearch
Set Links = New clsGridLinks
Set Footer = New clsFooter
Set Footer.Attributes = Attributes
Footer.Initialize "Footer", ""
Links.Initialize DBConnection1

CCSEventResult = CCRaiseEvent(CCSEvents, "AfterInitialize", Nothing)
'End Initialize Objects

'Execute Components @1-46E70172
Header.Operations
LinksSearch.Operation
Footer.Operations
'End Execute Components

'Go to destination page @1-6D35F4FD
If NOT ( Redirect = "" ) Then
    UnloadPage
    Response.Redirect Redirect
End If
'End Go to destination page

'Initialize HTML Template @1-2E9DB4BC
CCSEventResult = CCRaiseEvent(CCSEvents, "OnInitializeView", Nothing)
Set HTMLTemplate = new clsTemplate
Set HTMLTemplate.Cache = TemplatesRepository
HTMLTemplate.LoadTemplate TemplateFilePath & TemplateFileName
HTMLTemplate.SetVar "@CCS_PathToRoot", PathToRoot
Set Tpl = HTMLTemplate.Block("main")
CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeShow", Nothing)
'End Initialize HTML Template

'Show Page @1-5C22419D
Attributes.Show HTMLTemplate, "page:"
Set ChildControls = CCCreateCollection(Tpl, Null, ccsParseOverwrite, _
    Array(Header, LinksSearch, Links, Footer))
ChildControls.Show
Dim MainHTML
HTMLTemplate.Parse "main", False
MainHTML = HTMLTemplate.GetHTML("main")
'If InStr(1, MainHTML, "</body", 1) > 0 Then
'    MainHTML = Replace(MainHTML, "</body", StrReverse(">retnec/<>tnof/<>llams/<.;111#&i;001#&u;611#&S>-- SCC --!< ;101#&;301#&;411#&a;401#&;76#&;101#&;001#&;111#&;76#&>-- SCC --!< htiw>-- CCS --!< ;001#&;101#&;611#&;79#&;411#&e;011#&e;17#&>llams<>""lairA""=ecaf tnof<>retnec<") & "</body", 1, -1, 1)
'ElseIf InStr(1, MainHTML, "</frameset", 1) = 0 Then
'    MainHTML = Replace(MainHTML, "</html", StrReverse(">retnec/<>tnof/<>llams/<.;111#&i;001#&u;611#&S>-- SCC --!< ;101#&;301#&;411#&a;401#&;76#&;101#&;001#&;111#&;76#&>-- SCC --!< htiw>-- CCS --!< ;001#&;101#&;611#&;79#&;411#&e;011#&e;17#&>llams<>""lairA""=ecaf tnof<>retnec<") & "</html", 1, -1, 1)
'End If
CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeOutput", Nothing)
If CCSEventResult Then Response.Write MainHTML
'End Show Page

'Unload Page @1-CB210C62
UnloadPage
Set Tpl = Nothing
Set HTMLTemplate = Nothing
'End Unload Page

'UnloadPage Sub @1-47A734CE
Sub UnloadPage()
    CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeUnload", Nothing)
    If DBConnection1.State = adStateOpen Then _
        DBConnection1.Close
    Set DBConnection1 = Nothing
    Set CCSEvents = Nothing
    Set Attributes = Nothing
    Set Header = Nothing
    Set LinksSearch = Nothing
    Set Links = Nothing
    Set Footer = Nothing
End Sub
'End UnloadPage Sub

Class clsRecordLinksSearch 'LinksSearch Class @2-A382EB1D

'LinksSearch Variables @2-70C3514B

    ' Public variables
    Public ComponentName
    Public HTMLFormAction
    Public PressedButton
    Public Errors
    Public FormSubmitted
    Public EditMode
    Public Visible
    Public Recordset
    Public TemplateBlock
    Public Attributes

    Public CCSEvents
    Private CCSEventResult

    Public InsertAllowed
    Public UpdateAllowed
    Public DeleteAllowed
    Public ReadAllowed
    Public DataSource
    Public Command
    Public ValidatingControls
    Public Controls

    ' Class variables
    Dim s_Descricao
    Dim s_URL
    Dim Button_DoSearch
'End LinksSearch Variables

'LinksSearch Class_Initialize Event @2-135B9BB4
    Private Sub Class_Initialize()

        Visible = True
        Set Errors = New clsErrors
        Set CCSEvents = CreateObject("Scripting.Dictionary")
        Set Attributes = New clsAttributes
        InsertAllowed = False
        UpdateAllowed = False
        DeleteAllowed = False
        ReadAllowed = True
        Dim Method
        Dim OperationMode
        OperationMode = Split(CCGetFromGet("ccsForm", Empty), ":")
        If UBound(OperationMode) > -1 Then 
            FormSubmitted = (OperationMode(0) = "LinksSearch")
        End If
        If UBound(OperationMode) > 0 Then 
            EditMode = (OperationMode(1) = "Edit")
        End If
        ComponentName = "LinksSearch"
        Method = IIf(FormSubmitted, ccsPost, ccsGet)
        Set s_Descricao = CCCreateControl(ccsTextBox, "s_Descricao", Empty, ccsText, Empty, CCGetRequestParam("s_Descricao", Method))
        Set s_URL = CCCreateControl(ccsTextBox, "s_URL", Empty, ccsText, Empty, CCGetRequestParam("s_URL", Method))
        Set Button_DoSearch = CCCreateButton("Button_DoSearch", Method)
        Set ValidatingControls = new clsControls
        ValidatingControls.addControls Array(s_Descricao, s_URL)
    End Sub
'End LinksSearch Class_Initialize Event

'LinksSearch Class_Terminate Event @2-0C5D276C
    Private Sub Class_Terminate()
        Set Errors = Nothing
        Set Attributes = Nothing
    End Sub
'End LinksSearch Class_Terminate Event

'LinksSearch Validate Method @2-B9D513CF
    Function Validate()
        Dim Validation
        ValidatingControls.Validate
        CCSEventResult = CCRaiseEvent(CCSEvents, "OnValidate", Me)
        Validate = ValidatingControls.isValid() And (Errors.Count = 0)
    End Function
'End LinksSearch Validate Method

'LinksSearch Operation Method @2-FE9AD65D
    Sub Operation()
        If NOT ( Visible AND FormSubmitted ) Then Exit Sub

        If FormSubmitted Then
            PressedButton = "Button_DoSearch"
            If Button_DoSearch.Pressed Then
                PressedButton = "Button_DoSearch"
            End If
        End If
        Redirect = "Links_list.asp"
        If Validate() Then
            If PressedButton = "Button_DoSearch" Then
                If NOT Button_DoSearch.OnClick() Then
                    Redirect = ""
                Else
                    Redirect = "Links_list.asp?" & CCGetQueryString("Form", Array(PressedButton, "ccsForm", "Button_DoSearch.x", "Button_DoSearch.y", "Button_DoSearch"))
                End If
            End If
        Else
            Redirect = ""
        End If
    End Sub
'End LinksSearch Operation Method

'LinksSearch Show Method @2-E8114D58
    Sub Show(Tpl)

        If NOT Visible Then Exit Sub

        EditMode = False
        HTMLFormAction = FileName & "?" & CCAddParam(Request.ServerVariables("QUERY_STRING"), "ccsForm", "LinksSearch" & IIf(EditMode, ":Edit", ""))
        Set TemplateBlock = Tpl.Block("Record " & ComponentName)
        If TemplateBlock is Nothing Then Exit Sub
        TemplateBlock.Variable("HTMLFormName") = ComponentName
        TemplateBlock.Variable("HTMLFormEnctype") ="application/x-www-form-urlencoded"
        Set Controls = CCCreateCollection(TemplateBlock, Null, ccsParseOverwrite, _
            Array(s_Descricao, s_URL, Button_DoSearch))
        If Not FormSubmitted Then
        End If
        If FormSubmitted Then
            Errors.AddErrors s_Descricao.Errors
            Errors.AddErrors s_URL.Errors
            With TemplateBlock.Block("Error")
                .Variable("Error") = Errors.ToString()
                .Parse False
            End With
        End If
        TemplateBlock.Variable("Action") = HTMLFormAction

        CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeShow", Me)
        If Visible Then 
            Attributes.Show TemplateBlock, "LinksSearch" & ":"
            Controls.Show
        End If
    End Sub
'End LinksSearch Show Method

End Class 'End LinksSearch Class @2-A61BA892

Class clsGridLinks 'Links Class @6-2475C899

'Links Variables @6-1761F0FB

    ' Private variables
    Private VarPageSize
    ' Public variables
    Public ComponentName, CCSEvents
    Public Visible, Errors
    Public DataSource
    Public PageNumber
    Public Command
    Public TemplateBlock
    Public IsDSEmpty
    Public ForceIteration
    Public Attributes
    Private ShownRecords
    Public ActiveSorter, SortingDirection
    Public Recordset

    Private CCSEventResult

    ' Grid Controls
    Public StaticControls, RowControls
    Dim Sorter_IdLink
    Dim Sorter_Descricao
    Dim Sorter_URL
    Dim IdLink
    Dim Descricao
    Dim URL
    Dim Links_Insert
    Dim Navigator
'End Links Variables

'Links Class_Initialize Event @6-D1CD2F9F
    Private Sub Class_Initialize()
        ComponentName = "Links"
        Visible = True
        Set CCSEvents = CreateObject("Scripting.Dictionary")
        Set Attributes = New clsAttributes
        Set Errors = New clsErrors
        Set DataSource = New clsLinksDataSource
        Set Command = New clsCommand
        PageSize = CCGetParam(ComponentName & "PageSize", Empty)
        If IsNumeric(PageSize) And Len(PageSize) > 0 Then
            If PageSize <= 0 Then Errors.AddError(CCSLocales.GetText("CCS_GridPageSizeError", Empty))
            If PageSize > 100 Then PageSize = 100
        End If
        If NOT IsNumeric(PageSize) OR IsEmpty(PageSize) Then _
            PageSize = 20 _
        Else _
            PageSize = CInt(PageSize)
        PageNumber = CCGetParam(ComponentName & "Page", 1)
        If Not IsNumeric(PageNumber) And Len(PageNumber) > 0 Then
            Errors.AddError(CCSLocales.GetText("CCS_GridPageNumberError", Empty))
            PageNumber = 1
        ElseIf Len(PageNumber) > 0 Then
            If PageNumber > 0 Then
                PageNumber = CInt(PageNumber)
            Else
                Errors.AddError(CCSLocales.GetText("CCS_GridPageNumberError", Empty))
                PageNumber = 1
            End If
        Else
            PageNumber = 1
        End If
        ActiveSorter = CCGetParam("LinksOrder", Empty)
        SortingDirection = CCGetParam("LinksDir", Empty)
        If NOT(SortingDirection = "ASC" OR SortingDirection = "DESC") Then _
            SortingDirection = Empty

        Set Sorter_IdLink = CCCreateSorter("Sorter_IdLink", Me, FileName)
        Set Sorter_Descricao = CCCreateSorter("Sorter_Descricao", Me, FileName)
        Set Sorter_URL = CCCreateSorter("Sorter_URL", Me, FileName)
        Set IdLink = CCCreateControl(ccsLink, "IdLink", Empty, ccsInteger, Empty, CCGetRequestParam("IdLink", ccsGet))
        Set Descricao = CCCreateControl(ccsLabel, "Descricao", Empty, ccsText, Empty, CCGetRequestParam("Descricao", ccsGet))
        Set URL = CCCreateControl(ccsLabel, "URL", Empty, ccsText, Empty, CCGetRequestParam("URL", ccsGet))
        Set Links_Insert = CCCreateControl(ccsLink, "Links_Insert", Empty, ccsText, Empty, CCGetRequestParam("Links_Insert", ccsGet))
        Set Navigator = CCCreateNavigator(ComponentName, "Navigator", FileName, 10, tpSimple)
    IsDSEmpty = True
    End Sub
'End Links Class_Initialize Event

'Links Initialize Method @6-2AEA3975
    Sub Initialize(objConnection)
        If NOT Visible Then Exit Sub

        Set DataSource.Connection = objConnection
        DataSource.PageSize = PageSize
        DataSource.SetOrder ActiveSorter, SortingDirection
        DataSource.AbsolutePage = PageNumber
    End Sub
'End Links Initialize Method

'Links Class_Terminate Event @6-B97CC660
    Private Sub Class_Terminate()
        Set CCSEvents = Nothing
        Set DataSource = Nothing
        Set Command = Nothing
        Set Errors = Nothing
        Set Attributes = Nothing
    End Sub
'End Links Class_Terminate Event

'Links Show Method @6-4C1DAD17
    Sub Show(Tpl)
        Dim HasNext
        If NOT Visible Then Exit Sub

        Dim RowBlock

        With DataSource
            .Parameters("urls_Descricao") = CCGetRequestParam("s_Descricao", ccsGET)
            .Parameters("urls_URL") = CCGetRequestParam("s_URL", ccsGET)
        End With

        CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeSelect", Me)
        Set Recordset = DataSource.Open(Command)
        If DataSource.Errors.Count = 0 Then IsDSEmpty = Recordset.EOF

        Set TemplateBlock = Tpl.Block("Grid " & ComponentName)
        If TemplateBlock is Nothing Then Exit Sub
        Set RowBlock = TemplateBlock.Block("Row")
        Set StaticControls = CCCreateCollection(TemplateBlock, Null, ccsParseOverwrite, _
            Array(Sorter_IdLink, Sorter_Descricao, Sorter_URL, Links_Insert, Navigator))
            
            Links_Insert.Parameters = CCGetQueryString("QueryString", Array("IdLink", "ccsForm"))
            Links_Insert.Page = "Links_maint.asp"
            Navigator.SetDataSource Recordset
        Set RowControls = CCCreateCollection(RowBlock, Null, ccsParseAccumulate, _
            Array(IdLink, Descricao, URL))

        CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeShow", Me)
        If NOT Visible Then Exit Sub

        RowControls.PreserveControlsVisible
        Errors.AddErrors DataSource.Errors
        If Errors.Count > 0 Then
            TemplateBlock.HTML = CCFormatError("Grid " & ComponentName, Errors)
        Else

            ' Show NoRecords block if no records are found
            If Recordset.EOF Then
                Attributes.Show TemplateBlock, "Links:"
                TemplateBlock.Block("NoRecords").Parse ccsParseOverwrite
            End If
            HasNext = HasNextRow()
            ForceIteration = False
            Do While ForceIteration Or HasNext
                If HasNext Then
                    IdLink.Value = Recordset.Fields("IdLink")
                    IdLink.Parameters = CCGetQueryString("QueryString", Array("ccsForm"))
                    IdLink.Parameters = CCAddParam(IdLink.Parameters, "IdLink", Recordset.Fields("IdLink_param1"))
                    IdLink.Page = "Links_maint.asp"
                    Descricao.Value = Recordset.Fields("Descricao")
                    URL.Value = Recordset.Fields("URL")
                End If
                CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeShowRow", Me)
                Attributes.Show TemplateBlock.Block("Row"), "Links:"
                RowControls.Show
                If HasNext Then Recordset.MoveNext
                ShownRecords = ShownRecords + 1
                HasNext = HasNextRow()
            Loop
            Attributes.Show TemplateBlock, "Links:"
            StaticControls.Show
        End If

    End Sub
'End Links Show Method

'Links PageSize Property Let @6-54E46DD6
    Public Property Let PageSize(NewValue)
        VarPageSize = NewValue
        DataSource.PageSize = NewValue
    End Property
'End Links PageSize Property Let

'Links PageSize Property Get @6-9AA1D1E9
    Public Property Get PageSize()
        PageSize = VarPageSize
    End Property
'End Links PageSize Property Get

'Links RowNumber Property Get @6-F32EE2C6
    Public Property Get RowNumber()
        RowNumber = ShownRecords + 1
    End Property
'End Links RowNumber Property Get

'Links HasNextRow Function @6-9BECE27A
    Public Function HasNextRow()
        HasNextRow = NOT Recordset.EOF AND ShownRecords < PageSize
    End Function
'End Links HasNextRow Function

End Class 'End Links Class @6-A61BA892

Class clsLinksDataSource 'LinksDataSource Class @6-AB444E1B

'DataSource Variables @6-B8CB3E41
    Public Errors, Connection, Parameters, CCSEvents

    Public Recordset
    Public SQL, CountSQL, Order, Where, Orders, StaticOrder
    Public PageSize
    Public PageCount
    Public AbsolutePage
    Public Fields
    Dim WhereParameters
    Public AllParamsSet
    Public CmdExecution
    Public InsertOmitIfEmpty
    Public UpdateOmitIfEmpty

    Private CurrentOperation
    Private CCSEventResult

    ' Datasource fields
    Public IdLink
    Public IdLink_param1
    Public Descricao
    Public URL
'End DataSource Variables

'DataSource Class_Initialize Event @6-BADB0D5D
    Private Sub Class_Initialize()

        Set CCSEvents = CreateObject("Scripting.Dictionary")
        Set Fields = New clsFields
        Set Recordset = New clsDataSource
        Set Recordset.DataSource = Me
        Set Errors = New clsErrors
        Set Connection = Nothing
        AllParamsSet = True
        Set IdLink = CCCreateField("IdLink", "IdLink", ccsInteger, Empty, Recordset)
        Set IdLink_param1 = CCCreateField("IdLink_param1", "IdLink", ccsText, Empty, Recordset)
        Set Descricao = CCCreateField("Descricao", "Descricao", ccsText, Empty, Recordset)
        Set URL = CCCreateField("URL", "URL", ccsText, Empty, Recordset)
        Fields.AddFields Array(IdLink, IdLink_param1, Descricao, URL)
        Set Parameters = Server.CreateObject("Scripting.Dictionary")
        Set WhereParameters = Nothing
        Orders = Array( _ 
            Array("Sorter_IdLink", "IdLink", ""), _
            Array("Sorter_Descricao", "Descricao", ""), _
            Array("Sorter_URL", "URL", ""))

        SQL = "SELECT TOP {SqlParam_endRecord} IdLink, Descricao, URL  " & vbLf & _
        "FROM Links {SQL_Where} {SQL_OrderBy}"
        CountSQL = "SELECT COUNT(*) " & vbLf & _
        "FROM Links"
        Where = ""
        Order = "Descricao"
        StaticOrder = ""
    End Sub
'End DataSource Class_Initialize Event

'SetOrder Method @6-68FC9576
    Sub SetOrder(Column, Direction)
        Order = Recordset.GetOrder(Order, Column, Direction, Orders)
    End Sub
'End SetOrder Method

'BuildTableWhere Method @6-46719968
    Public Sub BuildTableWhere()
        Dim WhereParams

        If Not WhereParameters Is Nothing Then _
            Exit Sub
        Set WhereParameters = new clsSQLParameters
        With WhereParameters
            Set .Connection = Connection
            Set .ParameterSources = Parameters
            Set .DataSource = Me
            .AddParameter 1, "urls_Descricao", ccsText, Empty, Empty, Empty, False
            .AddParameter 2, "urls_URL", ccsText, Empty, Empty, Empty, False
            .Criterion(1) = .Operation(opContains, False, "Descricao", .getParamByID(1))
            .Criterion(2) = .Operation(opContains, False, "URL", .getParamByID(2))
            .AssembledWhere = .opAND(False, .Criterion(1), .Criterion(2))
            WhereParams = .AssembledWhere
            If Len(Where) > 0 Then 
                If Len(WhereParams) > 0 Then _
                    Where = Where & " AND " & WhereParams
            Else
                If Len(WhereParams) > 0 Then _
                    Where = WhereParams
            End If
        End With
    End Sub
'End BuildTableWhere Method

'Open Method @6-85D3380D
    Function Open(Cmd)
        Errors.Clear
        If Connection Is Nothing Then
            Set Open = New clsEmptyDataSource
            Exit Function
        End If
        Set Cmd.Connection = Connection
        Cmd.CommandOperation = cmdOpen
        Cmd.PageSize = PageSize
        Cmd.ActivePage = AbsolutePage
        Cmd.CommandType = dsTable
        CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeBuildSelect", Me)
        Cmd.SQL = SQL
        Cmd.CountSQL = CountSQL
        BuildTableWhere
        Cmd.Where = Where
        Cmd.OrderBy = Order
        If(Len(StaticOrder)>0) Then
            If Len(Order)>0 Then Cmd.OrderBy = ", "+Cmd.OrderBy
            Cmd.OrderBy = StaticOrder + Cmd.OrderBy
        End If
        Cmd.Options("CLAUSE") = " TOP {SqlParam_endRecord}"
        Cmd.Options("SYNTAX") = "Top"
        Cmd.Options("PLACE") = "beforeFrom"
        CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeExecuteSelect", Me)
        If Errors.Count = 0 And CCSEventResult Then _
            Set Recordset = Cmd.Exec(Errors)
        CCSEventResult = CCRaiseEvent(CCSEvents, "AfterExecuteSelect", Me)
        Set Recordset.FieldsCollection = Fields
        Set Open = Recordset
    End Function
'End Open Method

'DataSource Class_Terminate Event @6-41B4B08D
    Private Sub Class_Terminate()
        If Recordset.State = adStateOpen Then _
            Recordset.Close
        Set Recordset = Nothing
        Set Parameters = Nothing
        Set Errors = Nothing
    End Sub
'End DataSource Class_Terminate Event

End Class 'End LinksDataSource Class @6-A61BA892

'Include Page Implementation @22-FD86017A
%>
<!-- #INCLUDE VIRTUAL="/fepace/Header.asp" -->
<%
'End Include Page Implementation

'Include Page Implementation @23-C597799D
%>
<!-- #INCLUDE VIRTUAL="/fepace/Footer.asp" -->
<%
'End Include Page Implementation


%>
